package com.yonyou.pmclouds.safetyrectification.acceptrecord.service.rmiimpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.yonyou.pmclouds.ApplicationConsts;
import com.yonyou.pmclouds.basecom.bp.processor.AuditInfoInsertProcessor;
import com.yonyou.pmclouds.basecom.bp.template.SingleInsertBpTemplate;
import com.yonyou.pmclouds.basecom.consts.BillTypeConst;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.picture.entity.PictureParamVO;
import com.yonyou.pmclouds.picture.rmiitf.PictureRemoteService;
import com.yonyou.pmclouds.safetyrectification.acceptrecord.entity.AcceptRecordVO;
import com.yonyou.pmclouds.safetyrectification.acceptrecord.mapper.AcceptRecordMapper;
import com.yonyou.pmclouds.safetyrectification.acceptrecord.service.IAcceptRecordMaintain;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author tanghuan
 * @date 2019/10/26
 */
@Service(interfaceClass = IAcceptRecordMaintain.class, version = ApplicationConsts.APPLICATION_VERSION)
public class AcceptRecordMaintainImpl implements IAcceptRecordMaintain {
    @Autowired
    private AcceptRecordMapper mapper;
    @Autowired
    private PictureRemoteService pictureRemoteService;

    @Override
    public AcceptRecordVO add(AcceptRecordVO vo) throws BusinessException {
        SingleInsertBpTemplate<AcceptRecordVO> bp = new SingleInsertBpTemplate<>(mapper);
        bp.addBeforeProcessor(new AuditInfoInsertProcessor<AcceptRecordVO>());
        bp.insert(vo);

        // 保存图片
        PictureParamVO paramVO = new PictureParamVO(vo.getPkBill(), vo.getPkProject(),
                BillTypeConst.SAFETY_RECTIFICATION_BILLTYPE);
        pictureRemoteService.insertPictureForPub(vo, paramVO);

        return vo;
    }
}
